from flask import Blueprint, request, redirect

from ...common import helper
from ...extensions import tc

code_bp = Blueprint('Code', __name__, url_prefix='/api/check')


@code_bp.route("/simple_code", methods=["GET"])
def code_query_simple_code():
    uid = tc.get_token(request.form.get("code"))
    if uid is None:
        return redirect('/')
    else:
        return redirect('/?uid=' + uid)


@code_bp.route("/simple_code", methods=["POST"])
def code_check_simple_code():
    """

    检测简码是否存在

    :return:

    """
    return helper.success(data=tc.get_token(request.json.get("code")))
